<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>购物车</title>
</head>
<body>
    <!-- 宿主文件 -->
    <div id="app">
        <h2 :title="title">
            <!-- 插值表达式！ -->
            {{title}}
        </h2>
<!--        用户输入 -->
        <p>
            <input
                    type="text"
                    v-model="course"
                    v-on:keydown.enter="addCourse"
            >
            <button @click="addCourse">新增！</button>
        </p>
            <div v-for="c in courses" :key="c">
                <div>
                    {{ c }}
                </div>
            </div>

    </div>

    <script src="../js/vue.js"></script>
    <script>
        // 1、创建Vue的实例
        const app = new Vue({
            el: "#app",
            data() {
                return {
                    title: '开课吧，购物车!',
                    course: '',
                    courses: ['web全栈', 'web高级']
                }
            },
                methods: {
                addCourse() {
                    // 1、添加course到数组
                    this.courses.push(this.course)
                    // 2、清空course
                    this.course = ''
                }
            },
        })
    </script>
</body>
</html>
